package org.oslims.client.uicomponents.editbox;

import java.util.List;

import org.oslims.client.uicomponents.inputfields.SuggestionBoxInputField;
import org.oslims.domain.Request;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.VerticalPanel;

public class SelectRequestBox {

	final DialogBox selectRequestBox = new DialogBox(false, true);
	final VerticalPanel selectRequestBoxPanel = new VerticalPanel();

	final SuggestionBoxInputField requestField;

	final HorizontalPanel buttonLine = new HorizontalPanel();
	final Button okButton = new Button("OK");
	final Button cancelButton = new Button("Cancel");

	public SelectRequestBox(List<Request> requests) {
		selectRequestBox.setText("Select a Request");

		MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();

		for (Request r : requests) {
			oracle.add(r.getCode());
			GWT.log(r.getCode());
		}

		requestField = new SuggestionBoxInputField("request", "Request: ", "80px", "200px", oracle);

		selectRequestBoxPanel.add(requestField);
		buttonLine.add(okButton);
		buttonLine.add(cancelButton);

		selectRequestBoxPanel.add(buttonLine);

		selectRequestBox.add(selectRequestBoxPanel);
	}

	public void show(List<Request> requests) {
		selectRequestBox.center();
	}

	public void hide() {
		selectRequestBox.hide();
	}

	public HasValue<String> getRequestCode() {
		return requestField.getInputField();
	}

	public HasClickHandlers getOKButton() {
		return okButton;
	}

	public HasClickHandlers getCancelButton() {
		return cancelButton;
	}
}
